package com.ethank.controller.ocr;

import com.alibaba.fastjson2.JSONObject;
import com.ethank.common.core.domain.AjaxResult;
import com.ethank.service.impl.MailServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * @author tf
 * @date 2024-08-28
 * @Description
 */
@RequestMapping("/shop")
@RestController
public class ShopController {
    @Autowired
    private MailServiceImpl mailService;

    /**
     * @Description: 门店账单接收
     * @Param: [jsonObject]
     * @return: com.ethank.common.core.domain.AjaxResult
     * @Author: tf
     * @Date: 2024-08-28
     */
    @PostMapping("/adapterBill")
    public AjaxResult adapterBill(@RequestBody JSONObject jsonObject) {

        return mailService.adapterBill(jsonObject);
    }

    /**
     * @Description: 发送邮件
     * @Param: [jsonObject]
     * @return: com.ethank.common.core.domain.AjaxResult
     * @Author: tf
     * @Date: 2024-08-28
     */
    @PostMapping("/sendMail")
    public AjaxResult sendApprovalReminder(@RequestBody JSONObject jsonObject) {

        return mailService.sendWithHtml(jsonObject);
    }

    /**
     * @Description: 获取数据列表
     * @Param: []
     * @return: com.ethank.common.core.domain.AjaxResult
     * @Author: tf
     * @Date: 2024-08-28
     */
    @GetMapping("/getPageList")
    public AjaxResult getPageList(@RequestParam(value = "clientId", required = false) String clientId,
        @RequestParam(value = "atime", required = false) String atime,
        @RequestParam(value = "userId", required = false) String userId,
        @RequestParam(value = "emailHost", required = false) String emailHost,
        @RequestParam(value = "emailSource", required = false) String emailSource,
        @RequestParam(value = "emailPassword", required = false) String emailPassword,
        @RequestParam(value = "emailPort", required = false, defaultValue = "465") Integer emailPort,
        @RequestParam(value = "sign", required = false) String sign,
        @RequestParam(value = "loginStatus", required = false) Integer loginStatus) {
        return mailService.getPageList(clientId, atime, userId, emailHost, emailSource, emailPassword, emailPort, sign,
            loginStatus);
    }

    /**
     * @Description: 导出
     * @Param: [response]
     * @return: void
     * @Author: tf
     * @Date: 2024-08-28
     */
    @PostMapping("/export")
    public void download(HttpServletResponse response, @RequestBody JSONObject jsonObject) throws IOException {
        mailService.download(response, jsonObject);
    }

    /**
     * @Description:
     * @Param: [clientId]
     * @return: org.springframework.web.servlet.mvc.method.annotation.SseEmitter
     * @Author: tf
     * @Date: 2024-08-30
     */

    @GetMapping(value = "/sse", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitter buildConnect(@RequestParam String clientId) {
        return mailService.buildConnect(clientId);

    }

    @GetMapping("/stopSend")
    public AjaxResult stopEmail(@RequestParam String clientId) {
        return mailService.stopSendEmail(clientId);
    }

    /**
     * @Description: 线上账单列表
     * @Param: [shopId, atime]
     * @return: com.ethank.common.core.domain.AjaxResult
     * @Author: tf
     * @Date: 2024-09-18
     */
    @GetMapping("/getOnlineList")
    public AjaxResult getOnlineList(@RequestParam String shopId, @RequestParam String atime) {
        return mailService.getOnlineList(shopId, atime);
    }

    /**
     * @Description: 线下账单列表
     * @Param: [shopId, atime]
     * @return: com.ethank.common.core.domain.AjaxResult
     * @Author: tf
     * @Date: 2024-09-18
     */
    @GetMapping("/getOfflineList")
    public AjaxResult getOfflineList(@RequestParam String shopId, @RequestParam String atime) {
        return mailService.getOfflineList(shopId, atime);
    }

    /**
    * @Description: 获取抵现账单
    * @Param: [shopId, atime]
    * @return: com.ethank.common.core.domain.AjaxResult
    * @Author: tf
    * @Date: 2024-10-17
    */
    @GetMapping("/getCashBill")
    public AjaxResult getCashBill(@RequestParam String shopId, @RequestParam String atime) {
        return mailService.getCashBill(shopId, atime);
    }
    /**
    * @Description: 减免订单明细列表
    * @Param: [shopId, atime]
    * @return: com.ethank.common.core.domain.AjaxResult
    * @Author: tf
    * @Date: 2024-11-06
    */
    @GetMapping("/getFreeBillList")
    public AjaxResult getFreeBillList(@RequestParam Integer shopId, @RequestParam String atime) {
        return mailService.getFreeBillList(shopId, atime);
    }
    /**
    * @Description: 查询门店奖励明细
    * @Param: [shopId, atime]
    * @return: com.ethank.common.core.domain.AjaxResult
    * @Author: tf
    * @Date: 2024-11-05
    */
    @GetMapping("/getShopRewardList")
    public AjaxResult getShopRewardList(@RequestParam Integer shopId, @RequestParam String atime) {
        return mailService.getShopRewardList(shopId, atime);
    }

    /**
    * @Description: pc端获取详情展示html
    * @Param: [jsonObject]
    * @return: com.ethank.common.core.domain.AjaxResult
    * @Author: tf
    * @Date: 2024-10-17
    */
    @PostMapping("/getDisplayInfo")
    public AjaxResult getDisplayInfo(@RequestBody JSONObject jsonObject) {

        return mailService.getHtmlContent(jsonObject);
    }
    /**
    * @Description: 移动端面面面展示
    * @Param: [jsonObject]
    * @return: com.ethank.common.core.domain.AjaxResult
    * @Author: tf
    * @Date: 2024-10-17
    */
    @PostMapping("/getMobileDisplayInfo")
    public AjaxResult getMobileDisplayInfo(@RequestBody JSONObject jsonObject) {

        return mailService.getMobileDisplayInfo(jsonObject);
    }



}
